Repository navigation
Evaluator: a for loop's splat target collects what each gave, as ruby's does - #310
Conversation
…'s does `for *a in o` was a block of one parameter and `*a = __for`: of several values yielded it kept the first, and a bare yield gave [nil]. It takes |*__forv| and ruby's rule (pm_compile_for_node_index): the one value as an Array when Array.try_convert makes one of it, else the values. And a splat on a complex target, `for *h[:z] in o`, is read (it was a SyntaxError on both executions) and goes the same way. Several complex targets keep their way, and a splat among them is still refused.
284km
left a comment
There was a problem hiding this comment.
Reviewed 21ac1ec. No Critical / Major / Minor findings. The evaluator's for *a in o now binds through |*__forv| with ruby's rule: one value that Array.try_convert turns into an Array gives that Array, otherwise all the values. for *h[:z] and for *s.x now parse on both engines (they were SyntaxErrors). The other complex multi-targets are left as on main, with the ruby quirk for for s.x, b recorded as a separate item, so no new evaluator/VM difference is introduced. I ran corpus 830 and a probe on the author's build at this head, on the evaluator and MERE_RUBY_VM=1, against ruby 4.0.10: an each yielding 1, 2, [3, 4], nothing, nil and [5]; for *h[:z]; for *s.x; Arrays, [], nil and an Integer; and an object with to_ary. All identical. The description has vm_corpus 962 on the VM / 0 FAIL, run_corpus 962/962 and vm_check 246/246 on the rebased build. git merge-tree against main: clean. No mere-pr-review-watch inline comments. Merging.
On the evaluator,
for *a in okept only the first of several yielded values ([1]foryield 1, 2) and gave[nil]for a bareyield. Ruby gives[1, 2]and[], and the VM already did. #300's review found it.for *h[:z] in oandfor *s.x in owere SyntaxErrors on both executions; in ruby they take the same values asfor *a.Cause
The parser writes a for loop as
eachwith a block. A lone splat target was given one block parameter|__for|and the assignment*a = __for. One parameter keeps the first of several values and is nil for none.Ruby (pm_compile_for_node_index) takes the values as a rest parameter. If there is one value and
Array.try_convertmakes an Array of it, it uses that Array; then it assigns. Neither|x|nor|*x|alone does both.The for loop's own target reader (
parse_for_xtargets) did not accept*.Change (m_parse.mere,
parse_for)for *a(and a splat on an ivar) takes|*__forv|and applies ruby's rule first (for_rest_args). The calls (length,[],::Array.try_convert) are made, as ruby's sequence makes them.parse_for_xtargetsaccepts*in front of a target, as multiple assignment does. A lone splat on a complex target (for *h[:z]) goes the same way asfor *a.Left as on main (no new difference between the executions)
for s.x, b in [[1, 2]], ruby 4.0 sends the writer to one of the values (2.x = 1). The VM runs ruby's sequence and does the same; the evaluator binds[[1, 2], nil]as on main. Matching ruby's quirk on the evaluator is a separate item.for h[:k], *c) stays a SyntaxError on both executions, as on main. Ruby raises NoMethodError there, from the same quirk.Checked
for *aoveryield 1, 2/yield[1]/[nil][1, 2]/[][1, 2]/[][1, 2]/[]for *h[:z],for *s.xfor s.x, b in [[1, 2], [3, 4]][[[1, 2], nil], ...]for h[:k], *c in ofor *aover several values, one Array, one value, none, nested Arrays and nil;for x, *yandfor (d, e); splat on an index, an attribute and an ivar; an object whoseto_aryanswers; a loop that does not run; a method's locals. It matches ruby on both executions.vm_corpus.sh962 on the VM, 0 FAIL;run_corpus.sh962/962;vm_check.sh246/246. Main has since taken Validate Process.wait flags using native unsigned conversion #308 (Process.waitin m_driver.mere) and Add opt-in anonymous Class identity matching to Rails tests #309 (records), which this change does not touch.Record:
loop/2026-11-26-stage10-eval-for-splat.md.🤖 Generated with Claude Code